package com.briup.demo.mapper;

import com.briup.demo.User;
import org.apache.ibatis.annotations.*;

import java.time.LocalDateTime;
import java.util.List;


//在程序运行时 框架会自动生成接口的实现类对象，并交给spring的IOC容器管理
@Mapper//表示这是MyBatis中的Mapper接口
public interface UserMapper {

    //根据id查询用户
    public User getUserById(Integer id);


    //组合查询
    //查询姓李的用户，性别女，注册时间2023-07-04 15:59:10之后的，2024年11月26日10:46:57之前，结果降序
    @Select("select * from es_user where username like '%${username}%' AND gender = ${gender} " +
            "  AND register_time between #{startTime} AND #{endTime} " +//注意空格
            "  ORDER BY register_time DESC")
    public List<User> getUserList(@Param("username") String username,@Param("gender") Short gender,@Param("startTime") LocalDateTime startTime,@Param("endTime") LocalDateTime endTime);

    // 多条件查询用户信息
    public List<User> getUserByCondition(
            @Param("name") String name,
            @Param("status") Byte status,
            @Param("begin") LocalDateTime begin,
            @Param("end") LocalDateTime end
    );
    public List<User> getUserByConditionNew(
            @Param("name") String name,
            @Param("status") Byte status,
            @Param("begin") LocalDateTime begin,
            @Param("end") LocalDateTime end
    );
    //更新
    public void updateUser(User user);
    //新增
    @Options(useGeneratedKeys = true,keyProperty = "id")//要求返回主键 赋值给user对象的id属性上
    @Insert("insert into es_user (username,password,phone,gender,birthday,register_time) values (#{username},#{password},#{phone},#{gender},#{birthday},#{registerTime})")
    public void addUser(User user);


    //编辑
    //@Update("update es_user set username=#{username},password=#{password},phone=#{phone},avatar=#{avatar},gender=#{gender},status=#{status},birthday=#{birthday}, register_time=#{registerTime} where id=#{id}")
    //@Update("update t_user set phone=#{phone} where id=#{id}")
    //public void updateUser(User user);

    //根据id删除用户
    //@Delete("delete from es_user where id = #{id}")
    public void deleteByIdXML(Integer id);
}
